//
//  PrivateMessage.m
//  百车易车险
//
//  Created bychenxu on 14-8-29.
//  Copyright (c) 2014年 chenxu. All rights reserved.
//

#import "PrivateMessage.h"
#import "Login.h"

@implementation PrivateMessage
- (instancetype)init
{
    self = [super init];
    if (self) {
        _sendStatus = PrivateMessageStatusSendSucess;
    }
    return self;
}



#pragma mark  NSCoding

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_Talk forKey:@"msg_Talk"];
    [aCoder encodeObject:_extra forKey:@"msg_Extra"];
    [aCoder encodeInteger:_sender forKey:@"msg_sender"];
    [aCoder encodeObject:_count forKey:@"msg_count"];
    [aCoder encodeObject:_unreadCount forKey:@"msg_unreadcount"];
    [aCoder encodeObject:_id forKey:@"msg_id"];
    [aCoder encodeObject:_read_at forKey:@"msg_readat"];
    [aCoder encodeObject:_status forKey:@"msg_status"];
    [aCoder encodeObject:_created_at forKey:@"msg_creatat"];
    [aCoder encodeInteger:_sendStatus forKey:@"msg_sendstatus"];
    [aCoder encodeObject:_username forKey:@"msg_username"];

    
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    _Talk = [aDecoder decodeObjectForKey:@"msg_Talk"];
    _extra = [aDecoder decodeObjectForKey:@"msg_Extra"];
    _sender = [aDecoder decodeIntegerForKey:@"msg_sender"];
    _count = [aDecoder decodeObjectForKey:@"msg_count"];
    _unreadCount = [aDecoder decodeObjectForKey:@"msg_unreadcount"];
    _id = [aDecoder decodeObjectForKey:@"msg_id"];
    _read_at = [aDecoder decodeObjectForKey:@"msg_readat"];
    _status = [aDecoder decodeObjectForKey:@"msg_status"];
    _created_at = [aDecoder decodeObjectForKey:@"msg_creatat"];
    _sendStatus = [aDecoder decodeIntegerForKey:@"msg_sendstatus"];
    _username  = [aDecoder decodeObjectForKey:@"msg_username"];
    return self;
}

+ (instancetype)privateMessageWithObj:(id)obj andSender:(sender)sender andusername:(NSString *)username {
    PrivateMessage *nextMsg = [[PrivateMessage alloc] init];
    nextMsg.sender = sender;
    nextMsg.username = username;
    nextMsg.sendStatus = PrivateMessageStatusSending;
    nextMsg.created_at = [NSDate date];
    nextMsg.Talk = @"";
    nextMsg.extra = @"";
    if ([obj isKindOfClass:[NSString class]]) {
        nextMsg.Talk = obj;
    }else if ([obj isKindOfClass:[PrivateMessage class]]){
        PrivateMessage *originalMsg = (PrivateMessage *)obj;
        NSMutableString *content = [[NSMutableString alloc] initWithString:originalMsg.Talk];
        NSMutableString *extra = [[NSMutableString alloc] init];
        
        nextMsg.Talk = content;
        nextMsg.extra = extra;
    }
    return nextMsg;
};





@end
